package com.luoyuanxiangvip.admin.controller;


import com.luoyuanxiangvip.common.annotation.Cache;
import com.luoyuanxiangvip.core.service.IConfigService;
import com.luoyuanxiangvip.common.utils.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author luoyuanxiang <p>luoyuanxiangvip.com</p>
 * @since 2019-05-26
 */
@RestController
@RequestMapping("/admin/config")
@RequiresAuthentication
@Api(description = "系统管理")
public class ConfigController {

    @Resource
    private IConfigService iConfigService;

    @ApiOperation(value = "获取系统配置")
    @PostMapping("/list")
    public AjaxResult info(){
        return AjaxResult.success("获取系统配置成功", iConfigService.list());
    }

    @ApiOperation(value = "修改系统配置")
    @PostMapping("/update")
    @Cache(value = "修改系统配置", flush = true)
    public AjaxResult update(String key, String value) {
        boolean update = iConfigService.update().set("rel_value", value).eq("rel_key", key).update();
        return update ? AjaxResult.success("修改系统配置成功") : AjaxResult.error("修改系统配置失败");
    }

}
